<template>
  <div class="year">
    <div class="marks"></div>
    <list class="list">
      <cell class="listItem" v-for="(item, index) in longList" :key="index" @click="addClassFun(index, item)" :class="[nowYear === item ? 'active' : '']">
          <text class="text" :class="[nowYear === item ? 'active' : '']">{{item}}</text>
      </cell>
    </list>
  </div>
</template>
<script>
import store from '@/store/runStatus'

export default {
  name: 'year',
  data () {
    return {
      longList: ['2018', '2017', '2016', '2015'],
      activeIndex: 0
    }
  },
  methods: {
    addClassFun (index, item) {
      store.commit('changeYear', item)
      store.dispatch('getLedger', this)
      this.$emit('closeList')
    },
    initYear () {
      let arr = []
      for (let i = new Date().getFullYear(); i >= 2015; i--) {
        arr.push(i)
      }
      this.longList = arr
    }
  },
  created () {
    this.initYear()
  },
  computed: {
    nowYear () {
      return store.state.year
    }
  }
}
</script>
<style scoped>
.marks {
  width: 750px;
  background-color: rgba(0,0,0,0.4);
  position: relative;
  flex: 1;
}
.year{
  width: 750px;
  background-color: #fff;
  flex: 1;
}
.list{
  width: 750px;
  background-color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}
.listItem{
  width: 750px;
  height: 100px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding-left: 20px; 
  border-bottom-color: #f5f5f5;
  border-bottom-style: solid;
  border-bottom-width: 1px;
}
.text{
  font-size: 29.1px;
  font-family:PingFangSC-Regular;
  color:rgba(102,102,102,1);
}
.active{
  color: #fff;
  background-color: rgba(62,175,252,1);
}
</style>

